package gitlab_hook

import "jihulab.com/linksaas/proto-gen-go/events/events_gitlab"

type MergeRequestHook struct {
	ObjectKind       string           `json:"object_kind"`
	User             User             `json:"user"`
	ObjectAttributes ObjectAttributes `json:"object_attributes"`
	Changes          Changes          `json:"changes"`
	Project          Project          `json:"project"`
	Repository       Repository       `json:"repository"`
	Labels           []Label          `json:"labels"`
	Assignees        []Assignee       `json:"assignees"`
}

func (item *MergeRequestHook) ToProtoBuf() *events_gitlab.MergeRequestEvent {
	ret := &events_gitlab.MergeRequestEvent{
		ObjectKind:       item.ObjectKind,
		User:             item.User.ToProtoBuf(),
		ObjectAttributes: item.ObjectAttributes.ToProtoBuf(),
		Changes:          item.Changes.ToProtoBuf(),
		Project:          item.Project.ToProtoBuf(),
		Repository:       item.Repository.ToProtoBuf(),
		Labels:           []*events_gitlab.Label{},
		Assignees:        []*events_gitlab.Assignee{},
	}
	if item.Labels != nil {
		for _, label := range item.Labels {
			ret.Labels = append(ret.Labels, label.ToProtoBuf())
		}
	}
	if item.Assignees != nil {
		for _, assigness := range item.Assignees {
			ret.Assignees = append(ret.Assignees, assigness.ToProtoBuf())
		}
	}
	return ret
}
